package br.com.servlet;

import java.io.PrintWriter;
import java.sql.Connection;
import java.util.ArrayList;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.bean.BairroBean;
import br.com.bean.CidadeBean;
import br.com.bean.ClienteBean;
import br.com.bean.FuncionarioBean;
import br.com.connection.ConnectionFactory;
import br.com.controller.ControllerBairro;
import br.com.controller.ControllerCidade;
import br.com.controller.ControllerCliente;
import br.com.controller.ControllerFuncionario;
import br.com.view.FabricaHtml;


public class CadWindows extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public CadWindows() {
        super();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
		doExecute(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) {
		doExecute(request, response);
	}


	protected void doExecute(HttpServletRequest request, HttpServletResponse response) {
		try {
			Connection conn = new  ConnectionFactory().getConnection();
			PrintWriter out = response.getWriter();
			String typy = request.getParameter("tipo");
			ArrayList<CidadeBean> cidadeBean = ControllerCidade.listaCidade(conn);
			ArrayList<ClienteBean> clienteBean = ControllerCliente.listaCliente(conn);
			ArrayList<BairroBean> bairroBean = ControllerBairro.listaBairro(conn);
			ArrayList<FuncionarioBean> funcionarioBean = ControllerFuncionario.listaFuncionario(conn);
			if(typy.equals("responsavel")){
				out.print(FabricaHtml.criarParagraf("validateTips", "Os campos marcados s&atilde;o obrigat&oacute;rios!"));
				out.print(FabricaHtml.criarForm("formulario", "javascript:func()", "post"));
				out.print(FabricaHtml.criarDivSemFec("tab"));
				out.print(FabricaHtml.criarFieldsetIni());
						out.print(FabricaHtml.criarDivSemFec("base1"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "responsavel"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "responsavel", "responsavel", "R"));
						out.append(FabricaHtml.criarLabel("nome","Nome"));
						out.print(FabricaHtml.criarInput("text", "nome", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("nascimento", "Data Nascimento"));
						out.print(FabricaHtml.criarInput("text", "nascimento", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("cargo", "Cargo"));
						out.print(FabricaHtml.criarInput("text", "cargo", "text ui-widget-content ui-corner-all", ""));
						out.append(FabricaHtml.criarLabel("Cliente"));
						out.append(FabricaHtml.criarSelect("cliente", "cliente","text ui-widget-content ui-corner-all"));
						for (ClienteBean cliente : clienteBean) {
							out.append(FabricaHtml.criarOption(cliente.getId(), cliente.getRazao()));
						}
						out.append(FabricaHtml.fecharSelect());
				out.print(FabricaHtml.fechaDiv());
				out.print(FabricaHtml.fecharForm());
			}
			if(typy.equals("cliente")){
				out.print(FabricaHtml.criarParagraf("validateTips", "Os campos marcados s&atilde;o obrigat&oacute;rios!"));
				out.print(FabricaHtml.criarForm("formulario", "javascript:func()", "post"));
				out.print(FabricaHtml.criarDivSemFec("tab"));
				out.print(FabricaHtml.criarFieldsetIni());
						out.print(FabricaHtml.criarDivSemFec("base1"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "cliente"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "cliente", "cliente", "R"));
						out.append(FabricaHtml.criarLabel("razao","Razao"));
						out.print(FabricaHtml.criarInput("text", "razao", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("fantasia", "Fantasia"));
						out.print(FabricaHtml.criarInput("text", "fantasia", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("responsavel", "Responsavel"));
						out.print(FabricaHtml.criarInput("text", "responsavel", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("numero", "Numero"));
						out.print(FabricaHtml.criarInput("text", "numero", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("endereco", "Endereco"));
						out.print(FabricaHtml.criarInput("text", "endereco", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("telefone", "Telefone"));
						out.print(FabricaHtml.criarInput("text", "telefone", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("licenca", "Licenca"));
						out.print(FabricaHtml.criarInput("text", "licenca", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("honorario", "Honorario"));
						out.print(FabricaHtml.criarInput("text", "honorario", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("CNPJ", "CNPJ"));
						out.print(FabricaHtml.criarInput("text", "CNPJ", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("IE", "IE"));
						out.print(FabricaHtml.criarInput("text", "IE", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("suframa", "suframa"));
						out.print(FabricaHtml.criarInput("text", "SUFRAMA", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("ramo", "ramo"));
						out.print(FabricaHtml.criarInput("text", "Ramo", "text ui-widget-content ui-corner-all", ""));
						out.append(FabricaHtml.criarLabel("Cidade"));
						out.append(FabricaHtml.criarSelect("cidade", "cidade","text ui-widget-content ui-corner-all"));
						for (CidadeBean cidade : cidadeBean) {
							out.append(FabricaHtml.criarOption(cidade.getId(), cidade.getNome()));
						}
						out.append(FabricaHtml.fecharSelect());
						out.append(FabricaHtml.criarLabel("Bairro"));
						out.append(FabricaHtml.criarSelect("bairro", "bairro","text ui-widget-content ui-corner-all"));
						for (BairroBean bairro : bairroBean) {
							out.append(FabricaHtml.criarOption(BairroBean.getId(), bairro.getNome()));
						}
						out.append(FabricaHtml.fecharSelect());
				out.print(FabricaHtml.fechaDiv());
						out.print(FabricaHtml.criarFieldsetFim());
				out.print(FabricaHtml.fecharForm());
			}
			if(typy.equals("veiculo")){
				out.print(FabricaHtml.criarParagraf("validateTips", "Os campos marcados s&atilde;o obrigat&oacute;rios!"));
				out.print(FabricaHtml.criarForm("formulario", "javascript:func()", "post"));
				out.print(FabricaHtml.criarDivSemFec("tab"));
				out.print(FabricaHtml.criarFieldsetIni());
						out.print(FabricaHtml.criarDivSemFec("base1"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "veiculo"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "veiculo", "veiculo", "R"));
						out.append(FabricaHtml.criarLabel("tipo","Tipo"));
						out.print(FabricaHtml.criarInput("text", "tipo", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("marca", "Marca"));
						out.print(FabricaHtml.criarInput("text", "marca", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("modeloAno", "Modelo/Ano"));
						out.print(FabricaHtml.criarInput("text", "modeloAno", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("kmInicial", "KM Incial"));
						out.print(FabricaHtml.criarInput("text", "kmInicial", "text ui-widget-content ui-corner-all", ""));
						out.append(FabricaHtml.criarLabel("Funcionario"));
						out.append(FabricaHtml.criarSelect("funcionario", "funcionario","text ui-widget-content ui-corner-all"));
						for (FuncionarioBean funcionario : funcionarioBean) {
							out.append(FabricaHtml.criarOption(funcionario.getId(), funcionario.getNome()));
						}
						out.append(FabricaHtml.fecharSelect());
						out.print(FabricaHtml.criarLabel("pintura", "Pintura"));
						out.print(FabricaHtml.criarInput("text", "pintura", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("pisca", "Pisca"));
						out.print(FabricaHtml.criarInput("text", "pisca", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("buzina", "Buzina"));
						out.print(FabricaHtml.criarInput("text", "buzina", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("motor", "Motor"));
						out.print(FabricaHtml.criarInput("text", "motor", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("lanterna", "Lanterna"));
						out.print(FabricaHtml.criarInput("text", "lanterna", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("farol", "Farol"));
						out.print(FabricaHtml.criarInput("text", "farol", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("pneus", "Pneus"));
						out.print(FabricaHtml.criarInput("text", "pneus", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("obs", "OBS."));
						out.print(FabricaHtml.criarInput("text", "obs", "text ui-widget-content ui-corner-all", ""));
				out.print(FabricaHtml.fechaDiv());
						out.print(FabricaHtml.criarFieldsetFim());
				out.print(FabricaHtml.fecharForm());
			}
			
			if(typy.equals("funcionario")){
				out.print(FabricaHtml.criarParagraf("validateTips", "Os campos marcados s&atilde;o obrigat&oacute;rios!"));
				out.print(FabricaHtml.criarForm("formulario", "javascript:func()", "post"));
				out.print(FabricaHtml.criarDivSemFec("tab"));
				out.print(FabricaHtml.criarFieldsetIni());
						out.print(FabricaHtml.criarDivSemFec("base1"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "funcionario"));
						out.print(FabricaHtml.criarInputsOcultos("hidden", "funcionario", "funcionario", "R"));
						out.append(FabricaHtml.criarLabel("nome","Nome"));
						out.print(FabricaHtml.criarInput("text", "nome", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("salario", "Salario"));
						out.print(FabricaHtml.criarInput("text", "salario", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("cargo", "Cargo"));
						out.print(FabricaHtml.criarInput("text", "cargo", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("cpf", "CPF"));
						out.print(FabricaHtml.criarInput("text", "cpf", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("cnh", "CNH"));
						out.print(FabricaHtml.criarInput("text", "cnh", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("numero", "Numero"));
						out.print(FabricaHtml.criarInput("text", "numero", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("endereco", "Endereco"));
						out.print(FabricaHtml.criarInput("text", "endereco", "text ui-widget-content ui-corner-all", ""));
						out.print(FabricaHtml.criarLabel("telefone", "Telefone"));
						out.print(FabricaHtml.criarInput("text", "telefone", "text ui-widget-content ui-corner-all", ""));
						out.append(FabricaHtml.criarLabel("Cidade"));
						out.append(FabricaHtml.criarSelect("cidade", "cidade","text ui-widget-content ui-corner-all"));
						for (CidadeBean cidade : cidadeBean) {
							out.append(FabricaHtml.criarOption(cidade.getId(), cidade.getNome()));
						}
						out.append(FabricaHtml.fecharSelect());
						out.append(FabricaHtml.criarLabel("Bairro"));
						out.append(FabricaHtml.criarSelect("bairro", "bairro","text ui-widget-content ui-corner-all"));
						for (BairroBean bairro : bairroBean) {
							out.append(FabricaHtml.criarOption(BairroBean.getId(), bairro.getNome()));
						}
						out.append(FabricaHtml.fecharSelect());
						out.print(FabricaHtml.criarLabel("dataAdm", "Data Adm;o"));
						out.print(FabricaHtml.criarInput("text", "dataAdm", "text ui-widget-content ui-corner-all", ""));
				out.print(FabricaHtml.fechaDiv());
						out.print(FabricaHtml.criarFieldsetFim());
				out.print(FabricaHtml.fecharForm());
			}
			if(typy.equals("bairro")){
				out.print(FabricaHtml.criarParagraf("validateTips", "Os campos marcados s&atilde;o obrigat&oacute;rios!"));
				out.print(FabricaHtml.criarForm("formulario", "javascript:func()", "post"));
				out.print(FabricaHtml.criarDivSemFec("tab"));
				out.print(FabricaHtml.criarFieldsetIni());
						out.print(FabricaHtml.criarDivSemFec("base1"));
						out.append(FabricaHtml.criarLabel("nome","Nome"));
						out.print(FabricaHtml.criarInput("text", "nome", "text ui-widget-content ui-corner-all", ""));
						out.append(FabricaHtml.criarLabel("Cidade"));
						out.append(FabricaHtml.criarSelect("cidade", "cidade","text ui-widget-content ui-corner-all"));
						for (CidadeBean cidade : cidadeBean) {
							out.append(FabricaHtml.criarOption(cidade.getId(), cidade.getNome()));
						}
						out.append(FabricaHtml.fecharSelect());
				out.print(FabricaHtml.fechaDiv());
						out.print(FabricaHtml.criarFieldsetFim());
				out.print(FabricaHtml.fecharForm());
			}
				
			}catch (Exception e) {
e.printStackTrace();
}}}
